<?php


namespace App\Models\Concerns;

trait Common
{
    /**
     * @param array $data
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
     * @author Bob(bobcoder@qq.com)
     */
    public function saveData($data = [])
    {
        if (isset($data['id']) && $data['id']) {
            $model = $this->find($data['id']);
        } else {
            $model = $this->model;
        }
        foreach ($data as $key => $value) {
            $model->{$key} = $value;
        }
        $model->save();

        return $model;
    }
}
